package pyip.lib.mixtool.util.fyi;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 每月一号定期执行任务
 * @author yepeng
 * @date 2015年3月10日
 */
public class FYITimer {
    private static final Logger logger = LoggerFactory.getLogger(FYITimer.class);

    private static Timer timer;

    public static void start() {
        timer = new Timer();
        Calendar c = Calendar.getInstance();
        if (c.get(Calendar.DAY_OF_MONTH) != 1) {
            c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
            c.set(Calendar.DAY_OF_MONTH, 1);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
        }
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    System.out.println("新的一月又来啦");
                } catch (Exception e) {
                    logger.error("定时器出现异常", e);
                }
            }
        }, c.getTime(), 24 * 3600 * 1000);
    }
}
